package com.ssy.lingxi.contract.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.contract.model.vo.common.request.ContractInnerRecordPageVO;
import com.ssy.lingxi.contract.model.vo.common.request.ContractOuterRecordPageVO;
import com.ssy.lingxi.contract.model.vo.common.request.PurchaseMaterielPageVO;
import com.ssy.lingxi.contract.model.vo.common.response.ContractOuterRecordVO;
import com.ssy.lingxi.contract.model.vo.common.response.PageItemVO;
import com.ssy.lingxi.contract.model.vo.common.response.PurchaseMaterielQueryVO;
import com.ssy.lingxi.contract.model.vo.common.response.StatusVO;
import com.ssy.lingxi.contract.model.vo.coordination.request.AssociatedGoodsUpdateVO;
import com.ssy.lingxi.contract.model.vo.coordination.request.ContractCoordinationCommonPageVO;
import com.ssy.lingxi.contract.model.vo.coordination.request.ContractCoordinationExamineVO;
import com.ssy.lingxi.contract.model.vo.coordination.request.ContractCoordinationPageVO;
import com.ssy.lingxi.contract.model.vo.coordination.response.ContractCoordinationDetailVO;
import com.ssy.lingxi.contract.model.vo.coordination.response.ContractCoordinationInnerRecordVO;
import com.ssy.lingxi.contract.model.vo.coordination.response.ContractCoordinationQueryVO;
import com.ssy.lingxi.contract.service.*;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 合同能力-合同协同
 * @author 伍将
 * @date 2021/02/03
 * @version 2.0.0
 */
@RestController
@RequestMapping("/contract/coordination")
public class ContractCoordinationController extends BaseController {

    @Resource
    private IContractCoordinationService contractCoordinationService;

    @Resource
    private IContractPurchaseMaterielService purchaseMaterielService;

    @Resource
    private IContractOuterRecordService outerRecordService;

    @Resource
    private IContractInnerRecordService innerRecordService;

    @Resource
    private IStatusService statusService;

    /**
     * 合同查询-分页查询合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/pageList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCoordinationQueryVO>> pageList(HttpServletRequest httpRequest, @Valid ContractCoordinationPageVO pageVO) {
        return contractCoordinationService.pageList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 合同查询-查询合同详情
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/getDetail", method = RequestMethod.GET)
    public Wrapper<ContractCoordinationDetailVO> getDetail(HttpServletRequest httpRequest, Long contractId) {
        return contractCoordinationService.getDetail(getSysUser(httpRequest), contractId);
    }

    /**
     * 合同查询-查询合同详情-分页查询合同外部流转记录
     * @author 伍将
     * @date 2021/2/25
     **/
    @RequestMapping(value = "/pageOuterRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractOuterRecordVO>> pageOuterRecordList(HttpServletRequest httpRequest, @Valid ContractOuterRecordPageVO pageVO) {
        getSysUser(httpRequest);
        return outerRecordService.pageList(pageVO);
    }

    /**
     * 合同查询-查询合同详情-分页查询合同内部部流转记录
     * @author 伍将
     * @date 2021/2/25
     **/
    @RequestMapping(value = "/pageInnerRecordList", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCoordinationInnerRecordVO>> pageInnerRecordList(HttpServletRequest httpRequest, @Valid ContractInnerRecordPageVO pageVO) {
        return innerRecordService.pageCoordinationList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 合同查询-分页查询合同采购物料
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/pagePurchaseMaterielList", method = RequestMethod.GET)
    public Wrapper<PageData<PurchaseMaterielQueryVO>> pagePurchaseMaterielList(HttpServletRequest httpRequest, @Valid PurchaseMaterielPageVO pageVO) {
        return purchaseMaterielService.pageList(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核合同-分页查询待提交审核合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/pageToBeSubmitExamine", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCoordinationQueryVO>> pageToBeSubmitExamine(HttpServletRequest httpRequest, @Valid ContractCoordinationCommonPageVO pageVO) {
        return contractCoordinationService.pageToBeSubmitExamine(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待提交审核合同-关联报价商品
     * @author 伍将
     * @date 2021/3/2
     **/
    @RequestMapping(value = "/associatedOfferGoods")
    public Wrapper<Void> associatedOfferGoods(HttpServletRequest httpRequest, @RequestBody @Valid AssociatedGoodsUpdateVO updateVO) {
        return contractCoordinationService.associatedOfferGoods(getSysUser(httpRequest), updateVO);
    }

    /**
     * 待提交审核合同-提交审核
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/submitExamine")
    public Wrapper<Void> submitExamine(HttpServletRequest httpRequest, @RequestBody @Valid ContractCoordinationExamineVO examineVO) {
        return contractCoordinationService.submitExamine(getSysUser(httpRequest), examineVO);
    }

    /**
     * 待审核合同(一级)-分页查询待审核合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/pageToBeExamineOne", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCoordinationQueryVO>> pageToBeExamineOne(HttpServletRequest httpRequest, @Valid ContractCoordinationCommonPageVO pageVO) {
        return contractCoordinationService.pageToBeExamineOne(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核合同(一级)-审核合同
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/examineStepOne")
    public Wrapper<Void> examineStepOne(HttpServletRequest httpRequest, @RequestBody @Valid ContractCoordinationExamineVO examineVO) {
        return contractCoordinationService.examineStepOne(getSysUser(httpRequest), examineVO);
    }

    /**
     * 待审核合同(二级)-分页查询待审核合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/pageToBeExamineTwo", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCoordinationQueryVO>> pageToBeExamineTwo(HttpServletRequest httpRequest, @Valid ContractCoordinationCommonPageVO pageVO) {
        return contractCoordinationService.pageToBeExamineTwo(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待审核合同(二级)-审核合同
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/examineStepTwo")
    public Wrapper<Void> examineStepTwo(HttpServletRequest httpRequest, @RequestBody @Valid ContractCoordinationExamineVO examineVO) {
        return contractCoordinationService.examineStepTwo(getSysUser(httpRequest), examineVO);
    }

    /**
     * 待签订合同-分页查询待签订合同
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/pageToBeSign", method = RequestMethod.GET)
    public Wrapper<PageData<ContractCoordinationQueryVO>> pageToBeSign(HttpServletRequest httpRequest, @Valid ContractCoordinationCommonPageVO pageVO) {
        return contractCoordinationService.pageToBeSign(getSysUser(httpRequest), pageVO);
    }

    /**
     * 待签订合同-签订合同
     * @author 伍将
     * @date 2021/2/8
     **/
    @RequestMapping(value = "/sign")
    public Wrapper<Void> sign(HttpServletRequest httpRequest, @RequestBody @Valid ContractCoordinationExamineVO examineVO) {
        return contractCoordinationService.sign(getSysUser(httpRequest), examineVO);
    }

    /**
     * 合同查询-查询外部状态列表
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/getOuterStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getOuterStatusList() {
        return contractCoordinationService.getOuterStatusList();
    }

    /**
     * 合同查询-查询内部状态列表
     * @author 伍将
     * @date 2021/2/3
     **/
    @RequestMapping(value = "/getInnerStatusList", method = RequestMethod.GET)
    public Wrapper<List<PageItemVO>> getInnerStatusList() {
        return contractCoordinationService.getInnerStatusList();
    }

    /**
     * 状态查询
     * @author ds
     * @date 2021/5/28
     **/
    @RequestMapping(value = "/status/list", method = RequestMethod.GET)
    public Wrapper<StatusVO> statusList(HttpServletRequest httpRequest) {
        return statusService.getStatusByContractCoordination();
    }
}
